@extends('admin.common.base-master')

@section('html-head')
    <link href="{{url('css/admin/pagenum.css')}}" rel="stylesheet" />

@endsection

@section('html-body')
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="#">商品管理</a>
            <em></em>
        </div>
        @include('admin.common.goods-header')
        <div class="filter-box clearfix">

            <div class="fr">
                @if($type == 'product')
                    <a class="addBtn" href="{{route("Admin.Home.goodsSet")}}">新增</a>
                @else
                    <a class="addBtn" href="{{route("Admin.Home.enGoodsSet")}}">新增</a>
                @endif
            </div>
        </div>
        <div class="table-box">
            <table class="table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>商品名称</th>
                    <th>商品封面</th>
                    <th>商品分类</th>
                    <th>商品状态</th>
                    <th>商品排序</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @if(count($goodsProductList) > 0)
                    @foreach($goodsProductList as $good)
                        <tr id="goods_{{$good->id}}">
                            <td>{{$good->id}}</td>
                            <td>{{$good->name}}</td>
                            <td class="account-td" style="width: 5%;">
                                <span class="photo" style="border-radius: 100%;display:initial">
                                    @if($good->thumb_id != 0)
                                        <a target="_blank" href="{{$good->thumb_url}}" class="openimg" data-key="{{$good->thumb_id}}"><img src="{{$good->thumb_url}}" alt="{{$good->thumb_url}}"></a>
                                    @else
                                        <img src="{{url('images/default-avatar.png')}}" alt="">
                                    @endif
                                </span>
                            </td>
                            <td>{{$good->classify_name}}</td>
                            <td>@if($good->is_shop == 1)<span class="color4">上架</span> @else<span class="color3">下架</span> @endif</td>
                            <td>{{$good->sort}}</td>
                            <td style="overflow: visible;">
                                @if($type == 'product')
                                    <a class="color2" href="{{route("Admin.Home.goodsSet")}}?id={{$good->id}}">编辑</a>
                                @else
                                    <a class="color2" href="{{route("Admin.Home.enGoodsSet")}}?id={{$good->id}}">编辑</a>
                                @endif
                                <span>|</span>
                                <a href="javascript:void(0);" class="del" data-id="{{$good->id}}" data-type="{{$type}}">删除 </a>
                            </td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
            </table>
        </div>
        <div class="pagelist" style="text-align: center;">
            <?php echo $goodsProductList->render(); ?>
        </div>
    </div>

    <script>
        $(function(){



            $(document).on("click",".del",function(){
                var id   = $(this).attr("data-id");
                var type = $(this).attr("data-type");

                noty({
                    text: '你确定要删除吗?',
                    buttons: [
                        {addClass: 'btn btn-primary', text: '确定', onClick: function($noty) {
                            $noty.close();
                            $.ajax({
                                url:'{{route('Api.Admin.sys.delGoods')}}',
                                type:'post',
                                dataType:'json',
                                data:{id:id,type:type},
                                success:function(obj){
                                    if(obj.level == "success"){
                                        $("#goods_"+id).hide('slow');
                                    }else{
                                        noty({type:obj.level,text:obj.message,timeout:600});
                                    }
                                },
                                error:function(obj){
                                    console.log(obj);
                                }

                            });
                        }
                        },
                        {addClass: 'btn btn-danger', text: '取消', onClick: function($noty) {
                            $noty.close();
                        }
                        }
                    ]
                });

            });
        });
    </script>
@endsection